#!/bin/sh

echo $#

if [ $# -lt 10 ];then
 echo  csjappid pkgname splash  reward 	fullscreenvideo	banner	interactionexpress  umengkey umengchannel keyalis {appname icon res}
 exit 0
fi


rm -rf t
cp -a  r t

csjappid=$1
pkgname="$2"
csjsplash=$3
csjreward=$4
csjfullscreenvideo=$5
csjbanner=$6
csjinteraction=$7
umengkey=$8
umengchannel=$9
keyname=${10}

if [ $# -gt 10 ];then
  appname=${11}
fi
if [ $# -gt 11 ];then
  icon=${12}
fi
if [ $# -gt 12 ];then
  res=${13}
fi

#umeng UMConfigure;->init
sed -i "s/umengkey/$umengkey/" t/smali/com/xiaowanzi/plane/MyApplication.smali
sed -i "s/umengchannel/$umengchannel/" t/smali/com/xiaowanzi/plane/MyApplication.smali

#bytedance  TTAdConfig$Builder;->appI
#AdSlot\$Builder;->setCodeId|TTAdNative;->load
#getIdentifier
if [ "$csjappid" != "" ];then
	sed -i "s/csjappid/$csjappid/" t/smali/com/xiaowanzi/plane/ad/TTAdManagerHolder.smali
else
	echo appid is null
	exit 0
fi

if [ "$csjreward" != "" ];then
  sed -i "s/csjreward/$csjreward/" t/smali/com/xiaowanzi/plane/ad/AdUtil.smali
fi
if [ "$csjfeed" != "" ];then
  sed -i "s/csjfeed/$csjfeed/" t/smali_classes4/com/kuaikan/library/ad/nativ/sdk/TTNativeFeedAd.smali
fi
if [ "$csjsplash" != "" ];then
  sed -i "s/csjsplash/$csjsplash/" t/smali/com/xiaowanzi/plane/ad/AdUtil.smali
fi
if [ "$csjbanner" != "" ];then
  sed -i "s/csjbanner/$csjbanner/" t/smali/com/xiaowanzi/plane/ad/AdUtil.smali
fi
if [ "$csjinteraction" != "" ];then
  sed -i "s/csjinteraction/$csjinteraction/" t/smali/com/xiaowanzi/plane/ad/AdUtil.smali
fi
if [ "$csjfullscreenvideo" != "" ];then
  sed -i "s/csjfullscreenvideo/$csjfullscreenvideo/" t/smali/com/xiaowanzi/plane/ad/AdUtil.smali
fi
#pkgname

sed -i "s/renameManifestPackage: null/renameManifestPackage: $pkgname/" t/apktool.yml
sed -i "s/authorities=\"com.xiaowanzi.plane\./authorities=\"$pkgname./" t/AndroidManifest.xml

if [ "$appname" != "" ];then
	sed -i "s/火力飞机/$appname/" t/res/values/strings.xml
fi

if [ "$icon" != "" ];then
	for dst in t/res/mipmap-*/ic_launcher.png;do
		cp $icon $dst
	done
fi

if [ "$res" != "" ];then
	cp $res t/assets/00001.png
fi

apktool b -f t/
signapkj.sh  t/dist/*.apk  ~/junk/$umengchannel.apk ${keyname}
echo ~/junk/$umengchannel.apk
#mv t/dist/*.apk ~/junk/$umengchannel.apk

